import http from './index.js'


//文件上传
export const fileUpload = (url, data = {}) => {
  let formData = getFileUploadParams(data);
  let config = {
    headers: {
      'Content-Type': 'multipart/form-data'
    },
  }
  return http.post(url, formData, config);
};

const getFileUploadParams = (data = {}) => {
  const {name = 'file', file, params = {}} = data
  let formData = new FormData();
  for (const i in params) {
    formData.append(i, params[i])
  }
  formData.append(name, file)
  return formData
}

export {
  http,
}
